<template>
	<view class="content">
		<my-bar>
			<block slot="content">关于我们</block>
		</my-bar>
		<view class="about">
			<view class="about-content">
				<view class="qrcode">
					<!-- #ifdef APP-PLUS -->
					<image src="/static/logo.png" @longtap="save"></image>
					<!-- #endif -->
					<!-- #ifdef H5 -->
					<image src="/static/logo.png"></image>
					<!-- #endif -->
					<text class="tip">扫码体验好老师App模板</text>
				</view>
				<view class="desc">
					好老师是一个专为老师打造的教学分享平台，提高课堂的趣味性。
				</view>
				<view class="source">
					<view class="title"></view>
					<view class="source-list">
						<view class="source-cell">
							<text space="nbsp"></text>
							<text></text>
						</view>
						<view class="source-cell">
							<text space="nbsp"></text><text @click="openLink" class="link">{{sourceLink}}</text>
						</view>
					</view>
				</view>
				<!-- #ifdef APP-PLUS -->
				<button class="cu-btn bg-green lg " @click="share">分享</button>
				<!-- #endif -->
			</view>
			<!-- #ifdef APP-PLUS -->
			<view class="version">
				当前版本：{{version}}
			</view>
			<!-- #endif -->
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				providerList: [],
				version: '',
				sourceLink: ''
			}
		},
		// #ifdef APP-PLUS
		onLoad() {
			var that = this;
			plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
				//console.log(JSON.stringify(wgtinfo));
				//console.log(wgtinfo.version); //应用版本号
				that.version = wgtinfo.version;
			})

			uni.getProvider({
				service: 'share',
				success: (e) => {
					let data = [];
					for (let i = 0; i < e.provider.length; i++) {
						switch (e.provider[i]) {
							case 'weixin':
								data.push({
									name: '分享到微信好友',
									id: 'weixin'
								})
								data.push({
									name: '分享到微信朋友圈',
									id: 'weixin',
									type: 'WXSenceTimeline'
								})
								break;
							case 'qq':
								data.push({
									name: '分享到QQ',
									id: 'qq'
								})
								break;
							default:
								break;
						}
					}
					this.providerList = data;
				},
				fail: (e) => {
					console.log('获取登录通道失败' + JSON.stringify(e));
				}
			});
		},
		// #endif
		methods: {
			// #ifdef APP-PLUS
			save() {
				uni.showActionSheet({
					itemList: ['保存图片到相册'],
					success: () => {
						plus.gallery.save('/static/logo.png', function() {
							uni.showToast({
								title: '保存成功',
								icon: 'none'
							})
						}, function() {
							uni.showToast({
								title: '保存失败，请重试！',
								icon: 'none'
							})
						});
					}
				})
			},
			share(e) {
				if (this.providerList.length === 0) {
					uni.showModal({
						title: '当前环境无分享渠道!',
						showCancel: false
					})
					return;
				}
				let itemList = this.providerList.map(function(value) {
					return value.name
				})
				uni.showActionSheet({
					itemList: itemList,
					success: (res) => {
						uni.share({
							provider: this.providerList[res.tapIndex].id,
							scene: this.providerList[res.tapIndex].type && this.providerList[res.tapIndex].type === 'WXSenceTimeline' ?
								'WXSenceTimeline' : "WXSceneSession",
							type: 0,
							title: '欢迎使用好老师',
							summary: '好老师是一个专为老师打造的教学分享平台，提高课堂的趣味性',
							imageUrl: '/static/logo.png',
							href: "/static/logo.png",
							success: (res) => {
								console.log("success:" + JSON.stringify(res));
							},
							fail: (e) => {
								uni.showModal({
									content: e.errMsg,
									showCancel: false
								})
							}
						});
					}
				})
			},
			// #endif
			openLink() {
				if (plus) {
					plus.runtime.openURL(this.sourceLink);
				} else {
					window.open(this.sourceLink);
				}
			}
		}
	}
</script>

<style>
	image {
		width: 360upx;
		height: 360upx;
	}

	.about {
		flex-direction: column;
		flex: 1;

	}

	.about-content {
		flex: 1;
		padding: 30upx;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.qrcode {
		display: flex;
		align-items: center;
		flex-direction: column;
	}

	.qrcode .tip {
		margin-top: 20upx;
	}

	.desc {
		margin-top: 30upx;
		text-indent: 25px;
		display: block;
	}

	.code {
		color: #e96900;
		background-color: #f8f8f8;
	}

	button {
		width: 100%;
		margin-top: 40upx;
	}

	.version {
		height: 80upx;
		line-height: 80upx;
		justify-content: center;
		text-align: center;
		color: #ccc;
	}

	.source {
		margin-top: 30upx;
		flex-direction: column;
	}

	.source-list {
		flex-direction: column;
	}

	.link {
		color: #007AFF;
	}
</style>
